/*
 * @Author: Janssen000908 2601566046@qq.com
 * @Date: 2025-03-31 17:35:11
 * @LastEditors: Janssen000908 2601566046@qq.com
 * @LastEditTime: 2025-03-31 18:51:27
 * @FilePath: /linux_-demo/learn28/server.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

#include "comm.hpp"
using namespace std;

int main()
{
    //创建信道
    Init init;

    //打开信道
    int fd = open(FIFO_FILE,O_RDONLY);//需要等到写入端打开后，才会打开读端（反之一样）open阻塞
    if(fd  < 0)
    {
        perror("open");
        exit(FIFO_OPEN_ERR);
    }

    //通信(读)
    while(true)
    {
        char buffer[1024];
        int x = read(fd,buffer,sizeof(buffer));
        if(x > 0)
        {
            buffer[x] = 0;
            cout << "client: " << buffer << endl;
        }else if(x == 0)
        {
            cout << "client quit,server quit too!" << endl;
            break;
        }else{
            break;
        }
    }

    //关闭信道
    close(fd);

    return 0;
}